<template>
  <span>
    <el-button
      v-if="data.msgUrl && data.msgUrl !== ''"
      size="mini"
      plain
      circle
      type="info"
      icon="el-icon-view"
      title="跳转到单据"
      @click="navTo"
    />
    <a title="查看明细" @click="toView">{{ data.msgTitle }}</a>
  </span>
</template>
<script>
import { convertParamVal } from '@/utils/index'
import sysMsg from '@/api/system/SysMsg'

export default {
  components: { },
  props: {
    sup_this: {
      type: Object,
      required: true
    },
    data: {
      type: Object,
      required: true
    }
  },
  computed: {
    urlNav() {
      return this.data.msgUrl + '?sysGenCode=' + 'code001'
    }
  },
  methods: {
    toView() {
      const _this = this.sup_this.$refs.form
      _this.initDataOfBefore()
      _this.viewMainData(this.data.id)
    },
    navTo() {
      const msgUrlType = this.data.msgUrlType
      if (msgUrlType === 'page') {
        const msgUrl = this.data.msgUrl
        const str = msgUrl.split('?')
        const navPath = str[0]
        let queryObject = {}
        if (str.length > 1) {
          queryObject = convertParamVal(str[1])
        }
        this.$router.push({ path: navPath, query: queryObject })
        // 标识为已读
        const data = { idList: [this.data.id] }
        sysMsg.postRequestByName('doRead', data)
      }
    }
  }
}
</script>

<style scoped>
  div{
    display: inline-block;
    margin-right: 3px;
  }
</style>
